package com.wh.custom.controller;

import com.wh.basic.vo.AjaxResult;
import com.wh.custom.service.ICustomCustomerlabelService;
import com.wh.custom.pojo.CustomCustomerlabel;
import com.wh.custom.dto.CustomCustomerlabelQueryDto;
import com.wh.org.dao.IEmployeeDao;
import com.wh.sse.controller.SseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.List;

/**
* 后端接口类；
*/
@RestController
@RequestMapping("/customerLabel")
public class CustomLabelController {

    @Autowired
    public ICustomCustomerlabelService customCustomerlabelService;
    @Autowired
    private IEmployeeDao iEmployeeDao;
    @Autowired
    private SseController sseController;

    /**
     * 接口：添加或修改
     * @param customCustomerlabel 传递的实体
     * @return AjaxResult 响应给前端
     */
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody CustomCustomerlabel customCustomerlabel) {
        if ( customCustomerlabel.getId() != null){
            customCustomerlabelService.updateById(customCustomerlabel);
        }else{
            customCustomerlabelService.save(customCustomerlabel);
        }
        return new AjaxResult();
    }

    /**
     * 接口：删除
     * @param id
     * @return AjaxResult 响应给前端
     */
    @DeleteMapping(value = "/{id}")
    public AjaxResult del(@PathVariable("id") Long id) {
        customCustomerlabelService.removeById(id);
        return new AjaxResult();
    }

    /**
     * 接口：批量删除
     * @param ids
     * @return AjaxResult 响应给前端
     */
    @PatchMapping
    public AjaxResult patchDel(@RequestBody List<Long> ids) {
        customCustomerlabelService.removeByIds(ids);
        return new AjaxResult();
    }

    /**
     * 接口：查询单个对象
     * @param id
     */
    @GetMapping("/{id}")
    public CustomCustomerlabel findOne(@PathVariable("id") Long id) {
        return customCustomerlabelService.getById(id);
    }


    /**
     * 接口：查询所有
     * @return
     */
    @GetMapping
    public List<CustomCustomerlabel> findAll() {
        return customCustomerlabelService.list();
    }


    /**
     * 接口：分页查询或高级查询
     * @param customCustomerlabelQueryDto 查询对象
     * @return IPage<CustomCustomerlabel> 分页对象
     */
    @PostMapping
    public IPage<CustomCustomerlabel> findByPage(@RequestBody CustomCustomerlabelQueryDto customCustomerlabelQueryDto) {
        return customCustomerlabelService.findByPage(customCustomerlabelQueryDto);
    }
}
